package com.letwal.cmcvnd.create

import android.annotation.SuppressLint
import android.view.View
import androidx.lifecycle.ViewModel
import androidx.recyclerview.widget.GridLayoutManager
import com.letwal.cmcvnd.base.BaseActivity
import com.letwal.cmcvnd.create.adapter.MnemonicAdapter
import com.letwal.cmcvnd.adata.RevDataMnemonic
import com.letwal.cmcvnd.databinding.ActivityCreateWalletNewBinding
import com.letwal.cmcvnd.enums.PageTagEnum
import com.letwal.cmcvnd.extend.*

/** 创建钱包-展示backcode页 */
@SuppressLint("CustomSplashScreen")
class CreateWalletNewActivity : BaseActivity() {

    //布局binding
    private lateinit var mActivityBinding: ActivityCreateWalletNewBinding

    //适配器
    private lateinit var nMnemonicAdapter: MnemonicAdapter

    override fun onBindingViewModel(): List<ViewModel> {
        val list = mutableListOf<ViewModel>()
        return list
    }

    override fun onBindingViewTag(): String {
        return PageTagEnum.create_wallet_new.name.uppercase()
    }

    override fun onBindingContentView(): View {
        mActivityBinding =
            ActivityCreateWalletNewBinding.inflate(layoutInflater)
        return mActivityBinding.root
    }

    override fun onContentViewBinded() {
        try {
            //初始化适配器
            val email = intent.getStringExtra("email").toString()
            val password = intent.getStringExtra("password").toString()
            val zjc = intent.getStringExtra("zjc").toString()
            val list = zjc.toStringList()

            val testList = mutableListOf<RevDataMnemonic>()
            for (index in list.indices) {
                testList.add(RevDataMnemonic(index = (index+1), content = list[index]))
            }
            nMnemonicAdapter = MnemonicAdapter(testList)

            mActivityBinding.listCreateWalletNew.layoutManager = GridLayoutManager(this, 3)
            mActivityBinding.listCreateWalletNew.adapter = nMnemonicAdapter

            //点击确定
            mActivityBinding.submitCreateWalletNew.setOnClickListener {
                val params = HashMap<String, String>()
                params["email"] = email
                params["password"] = password
                params["zjc"] = zjc
                startToCreateWalletVerifyActivity(params)
            }

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

}